package Day04;

import java.util.Random;
import java.util.Scanner;
//假设有六个快递，六个快递柜
public class Demo03 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        int[] sum = new int[6];//取件码
        String[] g = new String[6];//公司名称
        int[] d = new int[6];//快递单号
        for (int i = 0; i < d.length; i++) {
            d[i] = 0;
        }
        while (true) {
            System.out.println("====欢迎使用新职课快递柜====");
            System.out.println("请输入您的身份：1-快递员，2-用户");
            int i = sc.nextInt();
            switch (i) {
                case 1: {
                    System.out.println("请选择操作：1-存快递 2-删除快递 3-修改快递信息 4-查看所有快递");
                    int b = sc.nextInt();
                    switch (b) {
                        case 1: {
                            System.out.println("请输入快递单号：");
                            int p = sc.nextInt();
                            int k = -1;
                            aa:
                            for (int j = 0; j < d.length; j++) {
                                if (d[j] == 0) {
                                    k = j;
                                    break aa;
                                }
                            }
                            if (k == -1) {
                                System.out.println("快递柜已满");
                            } else {
                                d[k] = p;
                                System.out.println("请输入公司名称:");
                                String next = sc.next();
                                g[k] = next;
                                int t = r.nextInt(900) + 100;
                                sum[k] = t;
                                System.out.println("快递存入成功，取件码是：" + sum[k]);
                            }
                            break;
                        }
                        case 2: {
                            System.out.println("请输入您要删除的快递单号：");
                            int e = sc.nextInt();
                            int c = -1;
                            for (int j = 0; j < d.length; j++) {
                                if (e == d[j]) {
                                    c = j;
                                }
                            }
                            if (c == -1) {
                                System.out.println("未找到快递");
                            } else {
                                d[c] = 0;
                                System.out.println("删除成功");
                            }
                            break;
                        }
                        case 3: {
                            System.out.println("请输入你要修改的快递单号：");
                            int f = sc.nextInt();
                            int c = -1;
                            for (int j = 0; j < d.length; j++) {
                                if (d[j] == f) {
                                    c = j;
                                }
                            }
                            if (c == -1) {
                                System.out.println("该快递单号不存在");
                            } else {
                                System.out.println("请输入新的快递单号：");
                                int m = sc.nextInt();
                                d[c] = m;
                                System.out.println("请输入新公司的名称");
                                String k = sc.next();
                                g[c] = k;
                                System.out.println("修改成功");
                            }
                            break;
                        }
                        case 4: {
                            int z = -1;
                            for (int j = 0; j < d.length; j++) {
                                if (d[j] != 0) {
                                    z = j;
                                }
                            }
                            if (z == -1) {
                                System.out.println("快递柜为空");
                            } else {
                                System.out.println("所有快递信息如下：");
                                for (int p = 0; p < sum.length; p++) {
                                    if (d[p] != 0) {
                                        System.out.println("快递单号\t公司名称\t取件码\t");
                                        System.out.println(d[p] + "\t" + g[p] + "\t" + sum[p] + "\t");
                                    }
                                }
                            }
                            break;
                        }
                    }
                    break;
                }
                case 2: {
                        System.out.println("请输入取件码：");
                        int c = sc.nextInt();
                        int s = -1;
                        for (int j = 0; j < sum.length; j++) {
                            if (c == sum[j] && d[j] != 0) {
                                s = j;
                            }
                        }
                        if (s == -1) {
                            System.out.println("未找到该快递");
                        } else {
                            d[s] = 0;
                            System.out.println("取件成功");
                        }
                        break;
                }
            }
        }
    }
}